﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml;
using System.Xml.Linq;

namespace ABC.Business.Models
{
    public class YandexModel
    {
        private const string token = "aa323da671bb3e416c7d155c237d23a8ccba99c60bb2657ea8f58bbc";

        public bool RegisterUser(string login, string password)
        {
            string url = @"https://pddimp.yandex.ru/reg_user_token.xml?token=" + token +
                         "&u_login=" + login +
                         "&u_password=" + password;
           
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "text/xml";

            var response = request.GetResponse();
            var reader = XmlReader.Create(response.GetResponseStream());
            var xml = XDocument.Load(reader);
            return xml.Descendants("ok").Any();
        }

        public bool EditUser(string login, string password, string iname, string fname, int sex, string hintq, string hinta)
        {
            string url = @"https://pddimp.yandex.ru/edit_user.xml?" +
                         "token=" + token +
                         "&login=" + login +
                         "&password=" + password +
                         "&iname=" + iname +
                         "&fname=" + fname +
                         "&sex=" + sex +
                         "&hintq=" + hintq +
                         "&hinta=" + hinta;
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "text/xml";
            var response = request.GetResponse();
            var reader = XmlReader.Create(response.GetResponseStream());
            var xml = XDocument.Load(reader);
            return xml.Descendants("ok").Any();
        }
    }
}
